package com.joinDepth.service;

import com.joinDepth.model.A;
import com.utils.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class BusinessService {
    private SessionFactory sessionFactory = new HibernateUtil().getSessionFactory();

    private void getA() {
        Session session = sessionFactory.openSession();
        Transaction tx = null;
        try {
            tx = session.beginTransaction();
            System.out.println("getA():executing session.get()");
            A customer = (A) session.get(A.class, 1L);
            System.out.println(customer.toString());
            tx.commit();

        } catch (RuntimeException e) {
            if (tx != null) {
                tx.rollback();
            }
            throw e;
        } finally {
            session.close();
        }
    }

    private void test() {
        getA();
        sessionFactory.close();
    }

    public static void main(String args[]) throws Exception {
        new BusinessService().test();
    }
}
